package servlet;

import hbase.HbaseUtil;
import org.apache.hadoop.hbase.client.HTableInterface;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
 * @Author:xuyuanhong
 * @Date:Created in 2022/3/13 10:50
 */

/**
 * @Author:xuyuanhong
 * @Date:Created in 2022/3/13 10:45
 */


@WebServlet(name = "ServletTable", urlPatterns = "/HBaseServletTable")
public class ServletTable extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String tname = request.getParameter("tablename");
        String msg="-";
        HTableInterface hbTable = null;
        PrintWriter pw=response.getWriter();
        String x=null;
        try {
//            List<Map<String, Object>> list = HbaseUtil.scan(tname);
//            Result result=(Result)HbaseUtil.scan(tname);
            msg = HbaseUtil.scan(tname);
            if (msg.equals("-")) {
                msg = "表格查询错误";
            } else {

                x = HbaseUtil.msg(tname);
                pw.write(x);

            }

        }catch (Exception e) {
            e.printStackTrace();
        }
//        pw.write(x);
        request.setAttribute("obj_data",x);
        request.getRequestDispatcher("/queryResult.jsp").forward(request,response);




    }
}
